<template>
    <div class="destination-card" @click="handleClick">
        <!-- 图片区域 -->
        <div class="card-image" :style="{ backgroundImage: `url(${destination.image})` }">
            <div class="image-overlay"></div>
            <div class="price-tag">{{ destination.price }}</div>
            <div class="wishlist-button" @click.stop="toggleWishlist">
                <svg :class="{ active: isWishlisted }" viewBox="0 0 24 24">
                    <path
                        d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" />
                </svg>
            </div>
        </div>

        <!-- 内容区域 -->
        <div class="card-content">
            <h3 class="destination-name">{{ destination.name }}</h3>
            <p class="destination-description">{{ destination.description }}</p>

            <!-- 标签区域 -->
            <div class="tags" v-if="destination.tags && destination.tags.length">
                <span v-for="(tag, index) in destination.tags" :key="index" class="tag">{{ tag }}</span>
            </div>

            <!-- 评分和按钮 -->
            <div class="card-footer">
                <div class="rating" v-if="destination.rating">
                    <span class="stars">★★★★★</span>
                    <span class="rating-value">{{ destination.rating }}</span>
                </div>
                <button class="explore-button" @click.stop="exploreDestination">
                    探索详情
                    <svg viewBox="0 0 24 24">
                        <path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" />
                    </svg>
                </button>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'DestinationCard',
        props: {
            destination: {
                type: Object,
                required: true,
                validator: value => {
                    return ['id', 'name', 'image', 'description', 'price'].every(key => key in value)
                }
            }
        },
        data() {
            return {
                isWishlisted: false
            }
        },
        methods: {
            handleClick() {
                this.$emit('click', this.destination.id)
            },
            toggleWishlist() {
                this.isWishlisted = !this.isWishlisted
                this.$emit('wishlist', {
                    id: this.destination.id,
                    isWishlisted: this.isWishlisted
                })
            },
            exploreDestination() {
                this.$emit('explore', this.destination.id)
            }
        }
    }
</script>

<style scoped>
    :root {
        --primary-color: #4a6bff;
        --secondary-color: #ff7e5f;
        --dark-color: #2d3436;
        --light-color: #f5f6fa;
        --text-color: #636e72;
        --white: #ffffff;
        --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        --border-radius: 12px;
        --transition: all 0.3s ease;
    }

    .destination-card {
        width: 100%;
        background: var(--white);
        border-radius: var(--border-radius);
        overflow: hidden;
        box-shadow: var(--shadow);
        transition: var(--transition);
        cursor: pointer;
        position: relative;
    }

    .destination-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    }

    /* 图片区域 */
    .card-image {
        height: 200px;
        background-size: cover;
        background-position: center;
        position: relative;
        overflow: hidden;
    }

    .image-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4));
        transition: var(--transition);
    }

    .destination-card:hover .image-overlay {
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.6));
    }

    .price-tag {
        position: absolute;
        top: 15px;
        right: 15px;
        background: rgba(255, 255, 255, 0.9);
        padding: 5px 12px;
        border-radius: 20px;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--primary-color);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    .wishlist-button {
        position: absolute;
        top: 15px;
        left: 15px;
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: var(--transition);
    }

    .wishlist-button:hover {
        background: var(--white);
        transform: scale(1.1);
    }

    .wishlist-button svg {
        width: 20px;
        height: 20px;
        fill: #dfe6e9;
        transition: var(--transition);
    }

    .wishlist-button svg.active {
        fill: var(--secondary-color);
    }

    /* 内容区域 */
    .card-content {
        padding: 20px;
    }

    .destination-name {
        margin: 0 0 10px 0;
        color: var(--dark-color);
        font-size: 1.3rem;
        font-weight: 600;
    }

    .destination-description {
        margin: 0 0 15px 0;
        color: var(--text-color);
        font-size: 0.95rem;
        line-height: 1.5;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* 标签区域 */
    .tags {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 15px;
    }

    .tag {
        background: #f0f4ff;
        color: var(--primary-color);
        padding: 4px 10px;
        border-radius: 4px;
        font-size: 0.75rem;
        font-weight: 500;
    }

    /* 底部区域 */
    .card-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 15px;
    }

    .rating {
        display: flex;
        align-items: center;
    }

    .stars {
        color: #ffc107;
        font-size: 0.9rem;
        letter-spacing: 1px;
    }

    .rating-value {
        margin-left: 5px;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--dark-color);
    }

    .explore-button {
        display: flex;
        align-items: center;
        background: var(--primary-color);
        color: var(--white);
        border: none;
        padding: 8px 15px;
        border-radius: 20px;
        font-size: 0.85rem;
        font-weight: 500;
        cursor: pointer;
        transition: var(--transition);
    }

    .explore-button:hover {
        background: #3a5bef;
        transform: translateX(3px);
    }

    .explore-button svg {
        width: 16px;
        height: 16px;
        fill: var(--white);
        margin-left: 5px;
        transition: var(--transition);
    }

    .explore-button:hover svg {
        transform: translateX(3px);
    }

    /* 响应式设计 */
    @media (max-width: 768px) {
        .card-image {
            height: 180px;
        }

        .card-content {
            padding: 15px;
        }

        .destination-name {
            font-size: 1.2rem;
        }

        .destination-description {
            font-size: 0.9rem;
        }

        .explore-button {
            padding: 6px 12px;
            font-size: 0.8rem;
        }
    }
</style>